package com.fu.consumer.controller;

import com.fu.core.common.JsonResult;
import com.fu.core.pojo.GoodsEsVo;
import com.fu.core.pojo.Notices;
import com.fu.core.pojo.SystemNotices;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.sql.Date;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 付龙江
 * @date 2022/1/29 11:07
 */
@RestController
@RequestMapping("/index")
@CrossOrigin
@Api(tags = "前台首页接口")
public class IndexController {



    @PostMapping("/historyAndHot")
    @ApiOperation(value = "点击搜索后弹出的大家都在看/历史搜索记录")
    public Map<String,Object> historyAndHot(){
        List<String> history = new ArrayList<>();
        history.add("西瓜");
        history.add("冬瓜");
        history.add("葡萄");
        history.add("栗子");
        history.add("香蕉");

        List<String> hot = new ArrayList<>();
        history.add("西瓜");
        history.add("冬瓜");
        history.add("葡萄");
        history.add("栗子");
        history.add("香蕉");

        JsonResult jsonResult = new JsonResult();
        jsonResult.setField("history",history);
        jsonResult.setField("hot",hot);
        jsonResult.setCode("200");
        return jsonResult.getMap();
    }


    @PostMapping("/goodsSearch")
    @ApiOperation(value = "商品搜索")
    @ApiImplicitParam(name = "name", value = "请输入关键词搜索商品", required = true, dataType = "String", paramType = "query")
    public Map<String,Object> goodsSearch(String name) throws Exception {
        List<GoodsEsVo> list = new ArrayList<>();
        for (int i = 0; i < 8; i++) {
            GoodsEsVo goodsEsVo = new GoodsEsVo(i,"新疆吐鲁番盆地大斜西瓜","大西瓜","西瓜","/都还没有图片",
                    new Timestamp(System.currentTimeMillis()),40.00,"个",800,4.20,1,new Date(System.currentTimeMillis()),"09:00:00",null,null);
            list.add(goodsEsVo);
        }
        JsonResult jsonResult = new JsonResult();
        jsonResult.setField("code",200);
        jsonResult.setField("data",list);
        return jsonResult.getMap();
    }

    @PostMapping("/myCity")
    @ApiOperation(value = "我的地址定位")
    @ApiImplicitParam(name = "city", value = "定位的城市名称（默认就是添加地址的城市，重新定位后就是新城市）", required = false, dataType = "String", paramType = "query")
    public Map<String,Object> myCity(String city) throws Exception {
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setField("city",city);
        return jsonResult.getMap();
    }

    @PostMapping("/indexBanner")
    @ApiOperation(value = "首页滚动的banner图片")
    public Map<String,Object> indexBanner(){
        Map<String,Object> map1 = new HashMap<>();
        map1.put("id","81684139");
        map1.put("img","http://47.108.60.93/ossImg/shopImg/4150caa47e11468cacff16ea0c0a3882.jpg");
        Map<String,Object> map2 = new HashMap<>();
        map2.put("id","81695318");
        map2.put("img","http://47.108.60.93/ossImg/shopImg/1feb69216023447b989cab0f1f301ef8.jpg");
        Map<String,Object> map3 = new HashMap<>();
        map3.put("id","81695680");
        map3.put("img","http://47.108.60.93/ossImg/shopImg/1cc9fde10e9447558c6a7a781bd0a5b0.jpg");
        Map<String,Object> map4 = new HashMap<>();
        map4.put("id","81695720");
        map4.put("img","http://47.108.60.93/ossImg/shopImg/f98c7db180924ac39dcdab0bef1c9cbf.jpg");
        List<Map<String,Object>> list = new ArrayList<>();
        list.add(map1);
        list.add(map2);
        list.add(map3);
        list.add(map4);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setField("banners",list);
        return jsonResult.getMap();
    }

    @PostMapping("/goodsDetail")
    @ApiOperation(value = "商品详情(用于首页banner或点击每个商品的简略图)")
    @ApiImplicitParam(name = "id", value = "商品编号", required = true, dataType = "Integer", paramType = "query")
    public Map<String,Object> goodsDetail(Long id) throws Exception {
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setField("goodsDetail","太复杂了，到时间看完成效果,评价也在里面");
        return jsonResult.getMap();
    }

    @PostMapping("/hotGoods")
    @ApiOperation(value = "热销商品")
    public Map<String,Object> hotGoods() throws Exception {

        List<GoodsEsVo> list = new ArrayList<>();
        for (int i = 0; i < 8; i++) {
            GoodsEsVo goodsEsVo = new GoodsEsVo(i,"新疆吐鲁番盆地大斜西瓜","大西瓜","西瓜","/都还没有图片",
                    new Timestamp(System.currentTimeMillis()),40.00,"个",800,4.20,1,new Date(System.currentTimeMillis()),"09:00:00",null,null);
            list.add(goodsEsVo);
        }
        JsonResult jsonResult = new JsonResult();
        jsonResult.setField("code",200);
        jsonResult.setField("data",list);
        return jsonResult.getMap();
    }

    @PostMapping("/newGoods")
    @ApiOperation(value = "新上商品")
    public Map<String,Object> newGoods() throws Exception {
        List<GoodsEsVo> list = new ArrayList<>();
        for (int i = 0; i < 8; i++) {
            GoodsEsVo goodsEsVo = new GoodsEsVo(i,"新疆吐鲁番盆地大斜西瓜","大西瓜","西瓜","/都还没有图片",
                    new Timestamp(System.currentTimeMillis()),40.00,"个",800,4.20,1,new Date(System.currentTimeMillis()),"09:00:00",null,null);
            list.add(goodsEsVo);
        }
        JsonResult jsonResult = new JsonResult();
        jsonResult.setField("code",200);
        jsonResult.setField("data",list);
        return jsonResult.getMap();
    }

    @PostMapping("/storeToRecommend")
    @ApiOperation(value = "店铺推荐商品")
    public Map<String,Object> storeToRecommend(){
        List<GoodsEsVo> list = new ArrayList<>();
        for (int i = 0; i < 8; i++) {
            GoodsEsVo goodsEsVo = new GoodsEsVo(i,"新疆吐鲁番盆地大斜西瓜","大西瓜","西瓜","/都还没有图片",
                    new Timestamp(System.currentTimeMillis()),40.00,"个",800,4.20,1,new Date(System.currentTimeMillis()),"09:00:00",null,null);
            list.add(goodsEsVo);
        }
        JsonResult jsonResult = new JsonResult();
        jsonResult.setField("code",200);
        jsonResult.setField("data",list);
        return jsonResult.getMap();
    }

    @PostMapping("/seckillGoods")
    @ApiOperation(value = "限时秒杀")
    @ApiImplicitParam(name = "time", value = "传秒杀的时间段（09:00:00，12:00:00, 15:00:00, 18:00:00）",
            required = false, dataType = "String", paramType = "query")
    public Map<String,Object> seckillGoods(String time){
        List<GoodsEsVo> list = new ArrayList<>();
        for (int i = 0; i < 8; i++) {
            GoodsEsVo goodsEsVo = new GoodsEsVo(i,"新疆吐鲁番盆地大斜西瓜","大西瓜","西瓜","/都还没有图片",
                    new Timestamp(System.currentTimeMillis()),40.00,"个",800,4.20,1,new Date(System.currentTimeMillis()),"09:00:00",null,null);
            list.add(goodsEsVo);
        }
        JsonResult jsonResult = new JsonResult();
        jsonResult.setField("code",200);
        jsonResult.setField("data",list);
        return jsonResult.getMap();
    }

    @PostMapping(value = "/systemNotices")
    @ApiOperation(value = "店铺公告")
    public Map<String,Object> systemNotices(){
        List<SystemNotices> list = new ArrayList<>();
        for (int i = 0; i < 5; i++) {
            SystemNotices systemNotices = new SystemNotices(i+1,"系统通知",new Timestamp(System.currentTimeMillis()),"请还没有结账的赶快结账");
            list.add(systemNotices);
        }
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setField("total",20);
        jsonResult.setField("Notices",list);
        return jsonResult.getMap();
    }


    @PostMapping(value = "/systemService")
    @ApiOperation(value = "平台客服")
    public Map<String,Object> systemService(){
        List<Notices> list = new ArrayList<>();
        for (int i = 0; i < 5; i++) {
           Notices notices = new Notices(1L,1,new Timestamp(System.currentTimeMillis()), new Timestamp(System.currentTimeMillis()),"帮我看下物流","ok");
            list.add(notices);
        }
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setField("total",20);
        jsonResult.setField("systemService",list);
        return jsonResult.getMap();
    }












}
